#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

void duplicateZeros(vector<int>& arr) {
    int n = arr.size();
    int i = -1, top = 0;
    while (top < n)
    {
        i++;
        if (arr[i] == 0) top += 2;
        else top += 1;
    }

    int j = n - 1;
    if (top == n + 1)
    {
        arr[j] = 0;
        j--, i--;
    }

    while (j >= 0)
    {
        arr[j] = arr[i];
        j--;
        if (arr[i] == 0)
        {
            arr[j] = arr[i];
            j--;
        }
        i--;
    }
}